/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements.  See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License.  You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package im.rtx.ui.frame;

import com.alee.extended.image.WebDecoratedImage;
import com.alee.extended.image.WebImage;
import com.alee.extended.layout.HorizontalFlowLayout;
import com.alee.extended.layout.VerticalFlowLayout;
import com.alee.extended.panel.GroupPanel;
import com.alee.laf.label.WebLabel;
import com.alee.laf.panel.WebPanel;
import com.alee.laf.splitpane.WebSplitPane;
import com.alee.laf.text.WebTextField;
import im.rtx.ui.component.base.BaseFrame;
import im.rtx.utils.ImageUtils;
import javafx.scene.layout.Border;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.swing.*;
import java.awt.*;

/**
 * Project  : rtx
 * Author   : solosky < solosky772@qq.com >
 * Created  : 11/22/14
 * License  : Apache License 2.0
 */
@Service
public class MainFrame extends BaseFrame {


    @PostConstruct
    public void init(){
        //this.initFrame();
        this.setSize(new Dimension(800, 600));
        this.setTitle("RTX");
        this.setResizable(true);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocationRelativeTo(null);

        // Left part content
        WebLabel leftLabel = new WebLabel ( "left", WebLabel.CENTER );
        leftLabel.setMargin ( 0 );
        leftLabel.setPreferredHeight(200);


        //左侧头像
        ImageIcon avatarIcon = getThemeService().getImageIcon("base/avatar/defaultAvatar");
        avatarIcon = ImageUtils.getScaledInstance(avatarIcon, 40, 40);
        WebDecoratedImage avatarImage = new WebDecoratedImage(avatarIcon);
        avatarImage.setShadeWidth(2);
        avatarImage.setRound(2);

        WebPanel nickPanel = new WebPanel(false);
        WebLabel nickLabel = new WebLabel("徐荣谦");
        nickLabel.setFontSize(16);
        WebLabel signLabel = new WebLabel("如果要再见，那请好好道声再见");
        signLabel.setForeground(Color.DARK_GRAY);

        nickPanel.setLayout(new VerticalFlowLayout());
        nickPanel.add(nickLabel);
        nickPanel.add(signLabel);
        nickPanel.setMargin(new Insets(6, 3, 3, 3));

        //search
        WebTextField searchFld = new WebTextField ();
        searchFld.setMargin (1 );
        ImageIcon searchIcon = getThemeService().getImageIcon("main/searchIcon");
        searchFld.setTrailingComponent ( new WebImage(  ImageUtils.getScaledInstance(searchIcon, 20, 20)) );
        searchFld.setPreferredHeight(25);
        searchFld.setInputPrompt("查找联系人..");
        searchFld.setInputPromptForeground(Color.decode("#D8D8D8"));
        searchFld.setDrawFocus(false);
        WebPanel searchPanel = new WebPanel(false);
        searchPanel.setMargin(2);
        searchPanel.add(searchFld);


        WebPanel headPanel = new WebPanel(false);
        headPanel.setLayout(new HorizontalFlowLayout());
        headPanel.setMargin(5);
        headPanel.add(avatarImage);
        headPanel.add(nickPanel);


        //左侧Tab切换栏
        WebPanel tabPanel = new WebPanel(false);
        ImageIcon tabBgIcon = getThemeService().getImageIcon("main/tabBg");
        tabPanel.setBackground(Color.black);

        //右侧好友栏
        WebPanel sessionPanel = new WebPanel(false);



        WebPanel bottomPanel = new WebPanel(false);
        bottomPanel.setLayout(new HorizontalFlowLayout());
        bottomPanel.add(tabPanel);
        bottomPanel.add(sessionPanel);

        WebPanel leftPanel = new WebPanel ( false );
        leftPanel.setLayout(new VerticalFlowLayout());
        leftPanel.add(headPanel);
        leftPanel.add(searchPanel);
        leftPanel.add(bottomPanel);

        // Right part content
        WebLabel rightLabel = new WebLabel ( "right", WebLabel.CENTER );
        rightLabel.setMargin ( 0 );
        WebPanel rightPanel = new WebPanel ( false, rightLabel);
        rightPanel.setBorder(null);

        // Split
        WebSplitPane splitPane = new WebSplitPane ( WebSplitPane.HORIZONTAL_SPLIT, leftPanel, rightPanel );
        splitPane.setOneTouchExpandable(false);
        //splitPane.setPreferredSize(new Dimension(250, 200));
        splitPane.setDividerLocation(230);
        splitPane.setContinuousLayout(true);
        splitPane.setDrawDividerBorder(false);
        splitPane.setMargin(0);
        splitPane.setBorder(null);
        splitPane.setDividerSize(1);

        this.add(splitPane);
    }
}
